﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Register.Model;
using Register.DAL;
using Register.Command;
using Register.BLL;
using System.Web.Script.Serialization;
namespace RegisterWeb.Manager.DoctorPersonalCenter.ashx
{
    /// <summary>
    /// AppointmentHandler 的摘要说明
    /// </summary>
    public class AppointmentHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action=context.Request["action"];
            #region 获取预约信息
            if (action.Equals("get")){
                int row = int.Parse(context.Request["rows"].ToString());
                int page = int.Parse(context.Request["page"].ToString());
                List<Register.Model.AppointmentInfo> list = new List<Register.Model.AppointmentInfo>();
                list = AppointmentBLL.GetPagedAppointmentInfoInfo(row, page, "   Doctor_ID=\'DO20120709002 \' ");  //临时模拟医生

                List<AppointmentInfoJSON> json = new List<AppointmentInfoJSON>();
                foreach (Register.Model.AppointmentInfo app in list)
                {
                    string status = "<img src='../../images/user_tick.png' />有效";
                    if (app.Appointment_Status.Equals("0"))
                    {
                        status = "<img src='../../images/user_cross.png' />无效";

                    }
                    json.Add(new AppointmentInfoJSON(Convert.ToString(app.Appointment_AddTime), Convert.ToString(app.Appointment_AlreadyRegisteredNumber), Convert.ToString(app.Appointment_DayTime), app.Appointment_ID, Convert.ToString(app.Appointment_LastNumber), HospitalInfoBLL.GetParamNameById(app.Appointment_OutpatientType), app.Appointment_Recoder, Convert.ToString(app.Appointment_RegisteredNumber), Convert.ToString(app.Appointment_RegistrationFee), status, HospitalInfoBLL.GetParamNameById(app.Appointment_TimeType), DoctorInfoBLL.GetDepartmentsNameById(app.Departments_ID), DoctorUserInfoBLL.GetDoctorNameById(app.Doctor_ID)));
                }

                AppointmentInfoListJSON appointmentInfoListJSON = new AppointmentInfoListJSON();
                appointmentInfoListJSON.total = AppointmentBLL.GetAppointmentInfoCount("  Doctor_ID=\'DO20120709002 \'  ");
                appointmentInfoListJSON.rows = json;

                JavaScriptSerializer jss = new JavaScriptSerializer();
                context.Response.Write(jss.Serialize(appointmentInfoListJSON));

            
            }
            #endregion
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
class AppointmentInfoListJSON
{

    public int total { get; set; }
    public List<AppointmentInfoJSON> rows { get; set; }

}
class AppointmentInfoJSON
{

    public string Appointment_ID
    {
        set;
        get;
    }
    public string Departments_ID
    {
        get;
        set;
    }
    public string Doctor_ID
    {
        get;
        set;
    }

    public string Appointment_LastNumber
    {
        get;
        set;
    }
    public string Appointment_TimeType
    {
        get;
        set;
    }
    public string Appointment_DayTime
    {
        get;
        set;
    }
    public string Appointment_OutpatientType
    {
        get;
        set;
    }
    public string Appointment_RegisteredNumber
    {
        get;
        set;
    }

    public string Appointment_RegistrationFee
    {
        get;
        set;
    }
    public string Appointment_AlreadyRegisteredNumber
    {
        get;
        set;
    }
    public string Appointment_Status
    {
        get;
        set;
    }
    public string Appointment_AddTime
    {
        get;
        set;

    }
    public string Appointment_Recoder
    {
        get;
        set;

    }
   
    public AppointmentInfoJSON(string Appointment_AddTime,string Appointment_AlreadyRegisteredNumber,string Appointment_DayTime,string Appointment_ID,string Appointment_LastNumber,string Appointment_OutpatientType,string Appointment_Recoder,string Appointment_RegisteredNumber,string Appointment_RegistrationFee,string Appointment_Status,string Appointment_TimeType,string Departments_ID,string Doctor_ID)
    {
        this.Appointment_AddTime = Appointment_AddTime;
        this.Appointment_AlreadyRegisteredNumber = Appointment_AlreadyRegisteredNumber;
        this.Appointment_DayTime = Appointment_DayTime;
        this.Appointment_ID = Appointment_ID;
        this.Appointment_LastNumber = Appointment_LastNumber;
        this.Appointment_OutpatientType = Appointment_OutpatientType;
        this.Appointment_Recoder = Appointment_Recoder;
        this.Appointment_RegisteredNumber = Appointment_RegisteredNumber;
        this.Appointment_RegistrationFee = Appointment_RegistrationFee;
        this.Appointment_Status = Appointment_Status;
        this.Appointment_TimeType = Appointment_TimeType;
        this.Departments_ID = Departments_ID;
        this.Doctor_ID = Doctor_ID;
        
    }
}